<template>
  <div>
    <van-search
      v-model="value"
      show-action
      placeholder="请输入搜索关键词"
      @cancel="onCancel"
    />

    <div class="cinema">
      <ul>
        <li v-for="data in computedCinemaList" :key="data.cinemaId">
          <!-- 影院和地址 -->
          <div class="address">
            <span>{{ data.name }}</span>
            <span>{{ data.address }}</span>
          </div>
          <!-- 价格和距离 -->
          <div class="cinema_price">
            <div>
              <span>￥{{ data.lowPrice/100 }}起</span>
            </div>
            <span class="cinema_gps">距离未知</span>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import { Search } from 'vant'
import { mapState, mapActions } from 'vuex'

Vue.use(Search)

export default {
  data () {
    return {
      value: ''
    }
  },
  methods: {
    onCancel () {
      // this.$router.push('/cinema')
      this.$router.replace('/cinema')
    },
    ...mapActions('CinemaModule', ['getCinemaList'])
  },
  mounted () {
    // console.log(this.$store.state.vuex_cinemaList)
    if (this.vuex_cinemaList.length === 0) {
      this.getCinemaList(this.cityId)
    } else {
      console.log('缓存')
    }
  },
  computed: {
    ...mapState('CityModule', ['cityId', 'cityName']),
    ...mapState('CinemaModule', ['vuex_cinemaList']),
    computedCinemaList () {
      if (this.value === '') return
      return this.vuex_cinemaList.filter(item => item.name.toUpperCase().includes(this.value.toUpperCase()) || item.address.toUpperCase().includes(this.value.toUpperCase()))
    }
  }
}
</script>

<style lang="scss" scoped>
  .van-search {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    overflow: hidden;
    z-index: 300;
  }

  .cinema {
    margin-top: 54px;
    height: 100%;
    overflow: hidden;
    position: relative;
  }
  ul li {
    height: 44px;
    border-bottom: 1px solid #ededed;
    font-size: 12px;
    padding: 15px;
    display: flex;
  }
  /* 影院地址 */
  .address {
    height: 45px;
    width: calc(100% - 70px);
    float: left;
  }
  .address span {
    display: block;
  }
  .address span:first-child {
    font-size: 15px;
    color: #191a1b;
  }
  .address span:last-child {
    color: #797d82;
    margin-top: 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* 价格和距离 */
  .cinema_price {
    float: right;
    height: 45px;
    width: 70px;
    text-align: center;
  }
  /* 价格的样式 */
  .cinema_price div span:first-child {
    font-size: 15px;
    color: #ff5f16;
  }

  .cinema_price .cinema_gps {
    font-weight: 400;
    display: block;
    margin-top: 5px;
    font-size: 11px;
    color: #797d82;
    text-align: center;
  }
</style>
